From 75439cafb6330da6c907f358ddc36ea92a0d46a4 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 12 Sep 2015 19:22:17 -0400 Subject: [PATCH] Move template support to qdata The hash table is only accessed at creation and destruction time, and many widgets don't use templates at all, so no need to have this permanently occupying space. --- gtk/gtkwidget.c | 28 +++++++++++++++++----------- gtk/gtkwidgetprivate.h | 4 ---- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index fd17c2e74b..1acbf6ec63 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -859,6 +859,7 @@ static GQuark quark_visual = 0; static GQuark quark_modifier_style = 0; static GQuark quark_enabled_devices = 0; static GQuark quark_size_groups = 0; +static GQuark quark_auto_children = 0; GParamSpecPool *_gtk_widget_child_property_pool = NULL; GObjectNotifyContext *_gtk_widget_child_property_notify_context = NULL; @@ -1025,6 +1026,7 @@ gtk_widget_class_init (GtkWidgetClass *klass) quark_modifier_style = g_quark_from_static_string ("gtk-widget-modifier-style"); quark_enabled_devices = g_quark_from_static_string ("gtk-widget-enabled-devices"); quark_size_groups = g_quark_from_static_string ("gtk-widget-size-groups"); + quark_auto_children = g_quark_from_static_string ("gtk-widget-auto-children"); style_property_spec_pool = g_param_spec_pool_new (FALSE); _gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE); @@ -12075,7 +12077,7 @@ gtk_widget_real_destroy (GtkWidget *object) GtkWidget *widget = GTK_WIDGET (object); GtkWidgetPrivate *priv = widget->priv; - if (priv->auto_children) + if (g_object_get_qdata (G_OBJECT (widget), quark_auto_children)) { GtkWidgetClass *class; GSList *l; @@ -12097,8 +12099,7 @@ gtk_widget_real_destroy (GtkWidget *object) #endif /* G_ENABLE_CONSISTENCY_CHECKS */ /* Release references to all automated children */ - g_hash_table_destroy (priv->auto_children); - priv->auto_children = NULL; + g_object_set_qdata (G_OBJECT (widget), quark_auto_children, NULL); #ifdef G_ENABLE_CONSISTENCY_CHECKS for (l = assertions; l; l = l->next) @@ -16672,21 +16673,26 @@ get_auto_child_hash (GtkWidget *widget, GType type, gboolean create) { + GHashTable *auto_children; GHashTable *auto_child_hash; - if (widget->priv->auto_children == NULL) + auto_children = (GHashTable *)g_object_get_qdata (G_OBJECT (widget), quark_auto_children); + if (auto_children == NULL) { if (!create) - return NULL; + return NULL; - widget->priv->auto_children = - g_hash_table_new_full (g_direct_hash, - NULL, - NULL, (GDestroyNotify)g_hash_table_destroy); + auto_children = g_hash_table_new_full (g_direct_hash, + NULL, + NULL, (GDestroyNotify)g_hash_table_destroy); + g_object_set_qdata_full (G_OBJECT (widget), + quark_auto_children, + auto_children, + (GDestroyNotify)g_hash_table_destroy); } auto_child_hash = - g_hash_table_lookup (widget->priv->auto_children, GSIZE_TO_POINTER (type)); + g_hash_table_lookup (auto_children, GSIZE_TO_POINTER (type)); if (!auto_child_hash && create) { @@ -16695,7 +16701,7 @@ get_auto_child_hash (GtkWidget *widget, NULL, (GDestroyNotify)g_object_unref); - g_hash_table_insert (widget->priv->auto_children, + g_hash_table_insert (auto_children, GSIZE_TO_POINTER (type), auto_child_hash); } diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h index 853143cc9f..7292aa8e07 100644 --- a/gtk/gtkwidgetprivate.h +++ b/gtk/gtkwidgetprivate.h @@ -165,10 +165,6 @@ struct _GtkWidgetPrivate GList *tick_callbacks; guint clock_tick_id; - /* A hash by GType key, containing hash tables by widget name - */ - GHashTable *auto_children; - GList *event_controllers; cairo_font_options_t *font_options; -- 2.30.2